<?php

    require ( 'init.inc.php' );
    require ( 'checkadmin.inc.php');
    require ( __COMM_PATH . 'pagecontrol.inc.php' );
    require ( __CLASS_PATH . 'page_list.class.php' );
	
	// -------------------------------------------------------
    // 接收变量
    // -------------------------------------------------------
    $action = $_REQUEST["action"];
    $type = intval($_POST['timemode']);
	$num  = intval($_POST['timenum']);
    // -------------------------------------------------------
    // 计算时间并读取数据
    // -------------------------------------------------------
   if ($action == "submit") {
	    $curdate = time();   //获得当前时间
        switch ($type) {
             case "1" :    
			              $schdate = $num == 0?(date("G") + 1) * 60 * 60:$num * 24 * 60 * 60;   //计算多少天前
						             
						  break;
            case "2" : 
						  $schdate = $num == 0?(date("w") + 1) * 24 * 60 * 60:$num * 7 * 24 * 60 *60;  //计算多少星期前
							     
						  break;
            case "3" : 
						  $schdate = $num == 0?date("j") * 24 * 60 * 60:$num * 30 * 24 * 60 * 60;  //计算多少月前
							  
						  break;
			case "4" :
						  $schdate = $num == 0?(date("z") + 1) * 24 * 60 * 60:$num * 365 * 24 * 60 * 60;  //计算多少年前
							
						  break;
				
        }
		   $tim= $curdate-$schdate;   //计算时间差
		   $result=$db->query("select `id`,`title`,`ordernum`,`planningprice`,`adduser`,`addtime` from `website_planning` where '$tim' <= `addtime` and  `addtime` < '$curdate'");
		
		  
	// -------------------------------------------------------
    // 生成销售报表
    // -------------------------------------------------------
		header("Content-Type: application/vnd.ms-excel");
		header("Accept-Ranges:bytes");
		header("Content-Disposition:attachment;filename=planning_".date('YmdHis').".xls"); //Execl文件名
		header("Pragma: no-cache");
		header("Expires: 0");
		echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"
		xmlns:x="urn:schemas-microsoft-com:office:excel"
		xmlns=" http://www.w3.org/TR/REC-html40">
		
		<meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT">
		<meta http-equiv=Content-Type content="text/html; charset=Utf-8">
		<!--[if gte mso 9]><xml>
		<x:ExcelWorkbook>
		<x:ExcelWorksheets>
		<x:ExcelWorksheet>
		<x:Name></x:Name>
		<x:WorksheetOptions>
		<x:DisplayGridlines/>
		</x:WorksheetOptions>
		</x:ExcelWorksheet>
		</x:ExcelWorksheets>
		</x:ExcelWorkbook>
		</xml><![endif]-->';
	   file_log($_SESSION['AdminUser'],"生成策划方案报表");
		echo "<table aling='left'><tr><td><strong>方案标题</strong></td><td><strong>方案费用</strong></td><td><strong>订单号</strong></td><td><strong>增加方案管理员</strong></td><td><strong>增加方案时间</strong></td></tr>";
		while($row=$db->fetch_array($result)){
			echo "<tr align='left'><td>".$row['title']."</td><td>".$row['planningprice']."</td><td>".$row['ordernum']."</td><td>".$row['adduser']."</td><td>".date("Y-m-d H:i:s",$row['addtime'])."</td></tr>";
		}
	    echo "</table>";
    }

?>